home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Hardware / PowerManager DDK 1.0f1 / Interfaces&Libraries / Interfaces / OSUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-08  |  11.9 KB  |  463 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Contains:    OS Utilities Interfaces.
  5.  
  6.      Version:    Mac OS 8
  7.  
  8.      DRI:        The last engineer to touch it
  9.  
  10.      Copyright:    © 1985-1999 by Apple Computer, Inc., all rights reserved
  11.  
  12.      Warning:    *** APPLE INTERNAL USE ONLY ***
  13.                  This file may contain unreleased API's
  14.  
  15.      BuildInfo:    Built by:            Scott Johnson
  16.                  On:                    10/8/99 11:26 AM
  17.                  With Interfacer:    3.0d13   (MPW PowerPC)
  18.                  From:                OSUtils.i
  19.                      Revision:        72
  20.                      Dated:            4/14/99
  21.                      Last change by:    NG
  22.                      Last comment:    Remove the for Carbon conditionals now that Carbon is
  23.  
  24.      Bugs:        Report bugs to Radar component "System Interfaces", "Latest"
  25.                  List the version information (from above) in the Problem Description.
  26.  
  27. */
  28. #ifndef __OSUTILS__
  29. #define __OSUTILS__
  30.  
  31. #ifndef __MACTYPES__
  32. #include <MacTypes.h>
  33. #endif
  34.  
  35. #ifndef __MIXEDMODE__
  36. #include <MixedMode.h>
  37. #endif
  38.  
  39. /*  HandToHand and other memory utilties were moved to MacMemory.h */
  40. #ifndef __MACMEMORY__
  41. #include <MacMemory.h>
  42. #endif
  43.  
  44. /*  GetTrapAddress and other trap table utilties were moved to Patches.h */
  45. #ifndef __PATCHES__
  46. #include <Patches.h>
  47. #endif
  48.  
  49. /*  Date and Time utilties were moved to DateTimeUtils.h */
  50. #ifndef __DATETIMEUTILS__
  51. #include <DateTimeUtils.h>
  52. #endif
  53.  
  54. #if !TARGET_OS_MAC
  55. #ifndef __ENDIAN__
  56. #include <Endian.h>
  57. #endif
  58.  
  59. #endif  /* !TARGET_OS_MAC */
  60.  
  61.  
  62.  
  63. #if PRAGMA_ONCE
  64. #pragma once
  65. #endif
  66.  
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70.  
  71. #if PRAGMA_IMPORT
  72. #pragma import on
  73. #endif
  74.  
  75. #if PRAGMA_STRUCT_ALIGN
  76.     #pragma options align=mac68k
  77. #elif PRAGMA_STRUCT_PACKPUSH
  78.     #pragma pack(push, 2)
  79. #elif PRAGMA_STRUCT_PACK
  80.     #pragma pack(2)
  81. #endif
  82.  
  83. enum {
  84.     useFree                        = 0,
  85.     useATalk                    = 1,
  86.     useAsync                    = 2,
  87.     useExtClk                    = 3,                            /*Externally clocked*/
  88.     useMIDI                        = 4
  89. };
  90.  
  91. enum {
  92.     false32b                    = 0,                            /*24 bit addressing error*/
  93.     true32b                        = 1                                /*32 bit addressing error*/
  94. };
  95.  
  96. enum {
  97.                                                                 /* result types for RelString Call */
  98.     sortsBefore                    = -1,                            /*first string < second string*/
  99.     sortsEqual                    = 0,                            /*first string = second string*/
  100.     sortsAfter                    = 1                                /*first string > second string*/
  101. };
  102.  
  103. enum {
  104.     dummyType                    = 0,
  105.     vType                        = 1,
  106.     ioQType                        = 2,
  107.     drvQType                    = 3,
  108.     evType                        = 4,
  109.     fsQType                        = 5,
  110.     sIQType                        = 6,
  111.     dtQType                        = 7,
  112.     nmType                        = 8
  113. };
  114.  
  115. typedef SignedByte                         QTypes;
  116.  
  117. struct SysParmType {
  118.     UInt8                             valid;
  119.     UInt8                             aTalkA;
  120.     UInt8                             aTalkB;
  121.     UInt8                             config;
  122.     short                             portA;
  123.     short                             portB;
  124.     long                             alarm;
  125.     short                             font;
  126.     short                             kbdPrint;
  127.     short                             volClik;
  128.     short                             misc;
  129. };
  130. typedef struct SysParmType                SysParmType;
  131.  
  132. typedef SysParmType *                    SysPPtr;
  133.  
  134. struct QElem {
  135.     struct QElem *                    qLink;
  136.     short                             qType;
  137.     short                             qData[1];
  138. };
  139. typedef struct QElem                    QElem;
  140. typedef QElem *                            QElemPtr;
  141. #if TARGET_OS_MAC
  142.  
  143. struct QHdr {
  144.     volatile short                     qFlags;
  145.     volatile QElemPtr                 qHead;
  146.     volatile QElemPtr                 qTail;
  147. };
  148. typedef struct QHdr                        QHdr;
  149. typedef QHdr *                            QHdrPtr;
  150. #else
  151. /*
  152.    QuickTime 3.0
  153.    this version of QHdr contains the Mutex necessary for
  154.    non-mac non-interrupt code
  155. */
  156.  
  157. struct QHdr {
  158.     volatile short                     qFlags;
  159.     short                             pad;
  160.     long                             MutexID;
  161.     volatile QElemPtr                 qHead;
  162.     volatile QElemPtr                 qTail;
  163. };
  164. typedef struct QHdr                        QHdr;
  165. typedef QHdr *                            QHdrPtr;
  166. #endif  /* TARGET_OS_MAC */
  167.  
  168. typedef CALLBACK_API( void , DeferredTaskProcPtr )(long dtParam);
  169. /*
  170.     WARNING: DeferredTaskProcPtr uses register based parameters under classic 68k
  171.              and cannot be written in a high-level language without 
  172.              the help of mixed mode or assembly glue.
  173. */
  174. typedef REGISTER_UPP_TYPE(DeferredTaskProcPtr)                     DeferredTaskUPP;
  175. #if OPAQUE_UPP_TYPES
  176.     EXTERN_API(DeferredTaskUPP)
  177.     NewDeferredTaskUPP               (DeferredTaskProcPtr        userRoutine);
  178.  
  179.     EXTERN_API(void)
  180.     DisposeDeferredTaskUPP           (DeferredTaskUPP            userUPP);
  181.  
  182.     EXTERN_API(void)
  183.     InvokeDeferredTaskUPP           (long                    dtParam,
  184.                                     DeferredTaskUPP            userUPP);
  185.  
  186. #else
  187.     enum { uppDeferredTaskProcInfo = 0x0000B802 };                     /* register no_return_value Func(4_bytes:A1) */
  188.     #define NewDeferredTaskUPP(userRoutine)                         (DeferredTaskUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  189.     #define DisposeDeferredTaskUPP(userUPP)                         DisposeRoutineDescriptor(userUPP)
  190.     #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  191.     #pragma parameter InvokeDeferredTaskUPP(__A1, __A0)
  192.     void InvokeDeferredTaskUPP(long dtParam, DeferredTaskUPP userUPP) = 0x4E90;
  193.     #else
  194.         #define InvokeDeferredTaskUPP(dtParam, userUPP)                 CALL_ONE_PARAMETER_UPP((userUPP), uppDeferredTaskProcInfo, (dtParam))
  195.     #endif
  196. #endif
  197. /* support for pre-Carbon UPP routines: NewXXXProc and CallXXXProc */
  198. #define NewDeferredTaskProc(userRoutine)                         NewDeferredTaskUPP(userRoutine)
  199. #define CallDeferredTaskProc(userRoutine, dtParam)                InvokeDeferredTaskUPP(dtParam, userRoutine)
  200.  
  201. struct DeferredTask {
  202.     volatile QElemPtr                 qLink;
  203.     short                             qType;
  204.     volatile short                     dtFlags;
  205.     DeferredTaskUPP                 dtAddr;
  206.     long                             dtParam;
  207.     long                             dtReserved;
  208. };
  209. typedef struct DeferredTask                DeferredTask;
  210. typedef DeferredTask *                    DeferredTaskPtr;
  211. #if TARGET_OS_MAC
  212.  
  213. struct MachineLocation {
  214.     Fract                             latitude;
  215.     Fract                             longitude;
  216.     union {
  217.         SInt8                             dlsDelta;                /* signed byte; daylight savings delta */
  218.         long                             gmtDelta;                /* use low 24-bits only */
  219.     }                                 u;
  220. };
  221. typedef struct MachineLocation            MachineLocation;
  222. #else
  223. /*
  224.     QuickTime 3.0:
  225.     Alignment of MachineLocation is weird. The union above used for delta
  226.     tends not to work on non-Mac compilers.
  227. */
  228.  
  229. struct MachineLocation {
  230.     Fract                             latitude;
  231.     Fract                             longitude;
  232.     BigEndianLong                     delta;                        /* high byte is daylight savings delta, low 24-bits is GMT delta */
  233. };
  234. typedef struct MachineLocation            MachineLocation;
  235. #endif  /* TARGET_OS_MAC */
  236.  
  237. EXTERN_API( Boolean )
  238. IsMetric                        (void)                                                        THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  239.  
  240. EXTERN_API( SysPPtr )
  241. GetSysPPtr                        (void)                                                        THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  242.  
  243.  
  244. /*
  245.     NOTE: SysBeep() has been moved to Sound.h.  
  246.           We could not automatically #include Sound.h in this file
  247.           because Sound.h indirectly #include's OSUtils.h which
  248.           would make a circular include.
  249. */
  250.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  251.                                                                                             #pragma parameter __D0 DTInstall(__A0)
  252.                                                                                             #endif
  253. EXTERN_API( OSErr )
  254. DTInstall                        (DeferredTaskPtr         dtTaskPtr)                            ONEWORDINLINE(0xA082);
  255.  
  256.  
  257.  
  258. #if TARGET_CPU_PPC || !TARGET_OS_MAC
  259. #define GetMMUMode() ((SInt8)true32b)
  260. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  261. #else
  262. EXTERN_API( SInt8 )
  263. GetMMUMode                        (void)                                                        TWOWORDINLINE(0x1EB8, 0x0CB2);
  264.  
  265.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  266.                                                                                             #pragma parameter SwapMMUMode(__A0)
  267.                                                                                             #endif
  268. EXTERN_API( void )
  269. SwapMMUMode                        (SInt8 *                mode)                                THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  270.  
  271. #endif
  272.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  273.                                                                                             #pragma parameter Delay(__A0, __A1)
  274.                                                                                             #endif
  275. EXTERN_API( void )
  276. Delay                            (unsigned long             numTicks,
  277.                                  unsigned long *        finalTicks)                            TWOWORDINLINE(0xA03B, 0x2280);
  278.  
  279. EXTERN_API( OSErr )
  280. WriteParam                        (void);
  281.  
  282.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  283.                                                                                             #pragma parameter Enqueue(__A0, __A1)
  284.                                                                                             #endif
  285. EXTERN_API( void )
  286. Enqueue                            (QElemPtr                 qElement,
  287.                                  QHdrPtr                 qHeader)                            ONEWORDINLINE(0xA96F);
  288.  
  289.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  290.                                                                                             #pragma parameter __D0 Dequeue(__A0, __A1)
  291.                                                                                             #endif
  292. EXTERN_API( OSErr )
  293. Dequeue                            (QElemPtr                 qElement,
  294.                                  QHdrPtr                 qHeader)                            ONEWORDINLINE(0xA96E);
  295.  
  296.  
  297.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  298.                                                                                             #pragma parameter __D0 SetCurrentA5
  299.                                                                                             #endif
  300. EXTERN_API( long )
  301. SetCurrentA5                    (void)                                                        THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  302.  
  303.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  304.                                                                                             #pragma parameter __D0 SetA5(__D0)
  305.                                                                                             #endif
  306. EXTERN_API( long )
  307. SetA5                            (long                     newA5)                                ONEWORDINLINE(0xC18D);
  308.  
  309.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  310.                                                                                             #pragma parameter __D0 InitUtil
  311.                                                                                             #endif
  312. EXTERN_API( OSErr )
  313. InitUtil                        (void)                                                        ONEWORDINLINE(0xA03F);
  314.  
  315.  
  316. #if TARGET_CPU_PPC
  317. EXTERN_API( void )
  318. MakeDataExecutable                (void *                    baseAddress,
  319.                                  unsigned long             length);
  320.  
  321. #endif  /* TARGET_CPU_PPC */
  322.  
  323.  
  324. #if TARGET_CPU_68K
  325. EXTERN_API( Boolean )
  326. SwapInstructionCache            (Boolean                 cacheEnable);
  327.  
  328. EXTERN_API( Boolean )
  329. SwapDataCache                    (Boolean                 cacheEnable);
  330.  
  331. EXTERN_API( void )
  332. FlushInstructionCache            (void)                                                        TWOWORDINLINE(0x7001, 0xA098);
  333.  
  334. EXTERN_API( void )
  335. FlushDataCache                    (void)                                                        TWOWORDINLINE(0x7003, 0xA098);
  336.  
  337. EXTERN_API( void )
  338. FlushCodeCache                    (void)                                                        ONEWORDINLINE(0xA0BD);
  339.  
  340. #endif  /* TARGET_CPU_68K */
  341.  
  342.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  343.                                                                                             #pragma parameter __D0 FlushCodeCacheRange(__A0, __A1)
  344.                                                                                             #endif
  345. EXTERN_API( OSErr )
  346. FlushCodeCacheRange                (void *                    address,
  347.                                  unsigned long             count)                                TWOWORDINLINE(0x7009, 0xA098);
  348.  
  349.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  350.                                                                                             #pragma parameter ReadLocation(__A0)
  351.                                                                                             #endif
  352. EXTERN_API( void )
  353. ReadLocation                    (MachineLocation *        loc)                                FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  354.  
  355.  
  356.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  357.                                                                                             #pragma parameter WriteLocation(__A0)
  358.                                                                                             #endif
  359. EXTERN_API( void )
  360. WriteLocation                    (const MachineLocation * loc)                                FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  361.  
  362.  
  363.  
  364. #if OLDROUTINENAMES
  365. #define IUMetric() IsMetric()
  366. #endif  /* OLDROUTINENAMES */
  367.  
  368. /*
  369.     NOTE: SysEnvirons is obsolete.  You should be using Gestalt.
  370. */
  371. /* Environs Equates */
  372. enum {
  373.     curSysEnvVers                = 2                                /*Updated to equal latest SysEnvirons version*/
  374. };
  375.  
  376.  
  377. struct SysEnvRec {
  378.     short                             environsVersion;
  379.     short                             machineType;
  380.     short                             systemVersion;
  381.     short                             processor;
  382.     Boolean                         hasFPU;
  383.     Boolean                         hasColorQD;
  384.     short                             keyBoardType;
  385.     short                             atDrvrVersNum;
  386.     short                             sysVRefNum;
  387. };
  388. typedef struct SysEnvRec                SysEnvRec;
  389. enum {
  390.                                                                 /* Machine Types */
  391.     envMac                        = -1,
  392.     envXL                        = -2,
  393.     envMachUnknown                = 0,
  394.     env512KE                    = 1,
  395.     envMacPlus                    = 2,
  396.     envSE                        = 3,
  397.     envMacII                    = 4,
  398.     envMacIIx                    = 5,
  399.     envMacIIcx                    = 6,
  400.     envSE30                        = 7,
  401.     envPortable                    = 8,
  402.     envMacIIci                    = 9,
  403.     envMacIIfx                    = 11
  404. };
  405.  
  406. enum {
  407.                                                                 /* CPU types */
  408.     envCPUUnknown                = 0,
  409.     env68000                    = 1,
  410.     env68010                    = 2,
  411.     env68020                    = 3,
  412.     env68030                    = 4,
  413.     env68040                    = 5
  414. };
  415.  
  416. enum {
  417.                                                                 /* Keyboard types */
  418.     envUnknownKbd                = 0,
  419.     envMacKbd                    = 1,
  420.     envMacAndPad                = 2,
  421.     envMacPlusKbd                = 3,
  422.     envAExtendKbd                = 4,
  423.     envStandADBKbd                = 5,
  424.     envPrtblADBKbd                = 6,
  425.     envPrtblISOKbd                = 7,
  426.     envStdISOADBKbd                = 8,
  427.     envExtISOADBKbd                = 9
  428. };
  429.  
  430.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  431.                                                                                             #pragma parameter __D0 SysEnvirons(__D0, __A0)
  432.                                                                                             #endif
  433. EXTERN_API( OSErr )
  434. SysEnvirons                        (short                     versionRequested,
  435.                                  SysEnvRec *            theWorld)                            ONEWORDINLINE(0xA090);
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443. #if PRAGMA_STRUCT_ALIGN
  444.     #pragma options align=reset
  445. #elif PRAGMA_STRUCT_PACKPUSH
  446.     #pragma pack(pop)
  447. #elif PRAGMA_STRUCT_PACK
  448.     #pragma pack()
  449. #endif
  450.  
  451. #ifdef PRAGMA_IMPORT_OFF
  452. #pragma import off
  453. #elif PRAGMA_IMPORT
  454. #pragma import reset
  455. #endif
  456.  
  457. #ifdef __cplusplus
  458. }
  459. #endif
  460.  
  461. #endif /* __OSUTILS__ */
  462.  
  463.